
from django.db import models
from django.db.models.enums import Choices

class BlockInfo(models.Model):
    # 限售总数
    time = models.BigIntegerField(null=True)
    number = models.CharField(max_length = 100, unique = True) 
    hash = models.CharField(max_length = 100, unique = True) 
    parentHash = models.CharField(max_length = 100) 
    stateRoot = models.CharField(max_length = 100) 
    extrinsicsRoot = models.CharField(max_length = 100) 
    authorId = models.CharField(max_length = 100) 
    finalized = models.BooleanField(default=False)
    class Meta:
        db_table = 'BlockInfo'
        indexes = [
            models.Index(
                fields=['number'],
                name='number_index',
            ),
            models.Index(
                fields=['hash'],
                name='hash_index',
            ),
            models.Index(
                fields=['time'],
                name='block_info_time_index',
            ),
        ]
    # 管理页面中的显示
    def __str__(self):
        return self.name

class BlockInfoLatest(models.Model):
    # 限售总数
    time = models.BigIntegerField(null=True)
    number = models.CharField(max_length = 100, unique = True) 
    hash = models.CharField(max_length = 100, unique = True) 
    extrinsics_count = models.BigIntegerField()
    transaction_count = models.BigIntegerField()
    class Meta:
        db_table = 'BlockInfoLatest'
        indexes = [
            models.Index(
                fields=['time'],
                name='block_info_last_time_index',
            ),
        ]
    # 管理页面中的显示
    def __str__(self):
        return self.name

class ExtrinsicsInfo(models.Model):
    block = models.ForeignKey("BlockInfo", on_delete = models.CASCADE)
    time = models.BigIntegerField(null=True)
    pallet = models.CharField(max_length = 100, null=True)
    method = models.CharField(max_length = 100, null=True)
    signature = models.CharField(max_length = 200, null=True)
    signer = models.CharField(max_length = 100, null=True)
    nonce = models.CharField(max_length = 100, null=True)
    args = models.TextField(null=True)
    hash = models.CharField(max_length = 100, null=True)
    partialFee = models.CharField(max_length = 100, null=True)
    success = models.BooleanField(default=False)
    paysFee = models.BooleanField(default=False)
    class Meta:
        db_table = 'ExtrinsicsInfo'
        indexes = [
            models.Index(
                fields=['time'],
                name='extrinsics_info_time_index',
            ),
            models.Index(
                fields=['hash'],
                name='extrinsics_hash_index',
            ),
        ]
    # 管理页面中的显示
    def __str__(self):
        return self.name

class EventInfo(models.Model):
    extrinsics = models.ForeignKey("ExtrinsicsInfo", on_delete = models.CASCADE)
    block = models.ForeignKey("BlockInfo", default = None, on_delete = models.CASCADE)
    time = models.BigIntegerField(null=True)
    pallet = models.CharField(max_length = 100, null = True)
    method = models.CharField(max_length = 100, null = True)
    data = models.TextField(null = True)
    class Meta:
        db_table = 'EventInfo'
        indexes = [
            models.Index(
                fields=['time'],
                name='event_info_time_index',
            ),
        ]
    # 管理页面中的显示
    def __str__(self):
        return self.name

class TransactionInfo(models.Model):
    extrinsics = models.ForeignKey("ExtrinsicsInfo", on_delete = models.CASCADE)
    block = models.ForeignKey("BlockInfo", default = None, on_delete = models.CASCADE)
    time = models.BigIntegerField(null=True)
    src = models.CharField(max_length = 100, null = True)
    dest = models.CharField(max_length = 100, null = True)
    amount = models.CharField(max_length = 100, null=True)

    class Meta:
        db_table = 'TransactionInfo'
        indexes = [
            models.Index(
                fields=['src'],
                name='src_index',
            ),
            models.Index(
                fields=['dest'],
                name='dest_index',
            ),
            models.Index(
                fields=['time'],
                name='transaction_info_time_index',
            ),
        ]
    # 管理页面中的显示
    def __str__(self):
        return self.name

class TransactionInfoLatest(models.Model):
    time = models.BigIntegerField(null=True)
    src = models.CharField(max_length = 100, null = True)
    dest = models.CharField(max_length = 100, null = True)
    amount = models.CharField(max_length = 100, null=True)
    hash = models.CharField(max_length = 100, null=True)

    class Meta:
        db_table = 'TransactionInfoLatest'
        indexes = [
            models.Index(
                fields=['time'],
                name='ti_last_time_index',
            ),
        ]
    # 管理页面中的显示
    def __str__(self):
        return self.name